<template>
  <div class="Cpass">
    <van-form @submit="onSubmit">
      <van-field
        v-model="oldpassword"
        type="password"
        name="请输入新密码"
        label="请输入新密码"
        placeholder="请输入新密码"
        :rules="[{ required: true, message: '请填写旧密码' }]"
      />
      <van-field
        v-model="newpassword"
        type="password"
        name="请输入新密码"
        label="请输入新密码"
        placeholder="请输入新密码"
        :rules="[{ required: true, message: '请填写新密码' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="再次输入密码"
        label="再次输入密码"
        placeholder="请再次输入新密码"
        :rules="[{ required: true, message: '请再次填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {updateUser} from '../../../../../api/user'
export default {
  data() {
    return {
      oldpassword: '',
      newpassword: '',
      password: '',
    };
  },
  methods: {
    onSubmit(values) {
      if (this.newPassword !== this.newRePassword) {
        Dialog({
          title: '提示',
          message: '两次密码输入不正确'
        })
      } else {
        // 请求修改密码接口
        updateUser({ oldPassword: this.oldpassword, newPassword: this.newpassword }).then(res => {
          console.log(res);
          if (res.code === 200) {
            this.$toast.success('修改成功')
            this.$router.push('/home/mine')
          } else if (res.code === 400) {
            this.$toast.fail(res.msg)
          }
        })
      }
    }
  },
}
</script>

<style>

</style>